package com.dotc.kotlinmvvmdemo.activity

import androidx.lifecycle.LifecycleObserver
import com.dotc.kotlinmvvmdemo.R
import com.dotc.kotlinmvvmdemo.bean.UserBean
import com.dotc.kotlinmvvmdemo.base.BaseActivity
import com.dotc.kotlinmvvmdemo.databinding.ActivityFunctionBinding
import com.dotc.kotlinmvvmdemo.viewModel.FunctionViewModel
import kotlinx.android.synthetic.main.activity_function.*

/**
 * 操作使用mvvm
 */
class FunctionActivity : BaseActivity<ActivityFunctionBinding, FunctionViewModel>()  {
    override fun modelClass(): Class<FunctionViewModel>? {
       return FunctionViewModel::class.java
    }

    override fun layout(): Int {
       return R.layout.activity_function
    }

    override fun initData() {
        //必须实现
        binding!!.viewModel=viewModel
        binding!!.lifecycleOwner=this
        //添加生命周期监听
        lifecycle.addObserver(viewModel as LifecycleObserver)
        binding!!.viewModel!!.context = this@FunctionActivity
        var userBean = UserBean("小明",29)
        binding!!.user = userBean
        var index = 0
        btn1.setOnClickListener {
            userBean.details.set("这是修改后的详情: ${++index}")
        }
    }

    override fun initObserve() {

    }


}